Skip to content

Added insertStructure() and subfunctions - #47

Merged
cebarboza merged 15 commits into
developfrom
21-function-to-create-extra-files-for-study-package
Jul 3, 2026
Merged

Added insertStructure() and subfunctions#47
cebarboza merged 15 commits into
developfrom
21-function-to-create-extra-files-for-study-package

Conversation

@laacri

@laacri laacri commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Added code for insertFunction(...) and the subfunctions:

  1. installPackageBundle(...)
  2. insertDocs(...)
  3. insertStudyFiles(...)
  4. insertTests(...)

Created test files:

  • test-insertStructure.R
  • Sample package tests/testthat/testPackage to run the tests

For now all the functions have a "default" behaviour, but parameters can be added in the future to install a different package bundle or customize study files. Also, for now they only impact the structure of the study folder and not the content (i.e. all newly created files are empty).

Closes #30, #31, #32, #33, #34 and #21.

@laacri laacri added this to the GitHub release v0.1.0 milestone Jun 8, 2026
@laacri
laacri requested a review from cebarboza June 8, 2026 14:44
@laacri laacri self-assigned this Jun 8, 2026
@laacri laacri added the enhancement New feature or request label Jun 8, 2026

@cebarboza cebarboza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes a minimum viable version. Probably we can just test it right away for the thrombo package.

Comment thread R/insertStructure.R
) {

# Need an existing package to run the function
if (!file.exists(file.path(path, "DESCRIPTION"))) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably for a next iteration we can put a check like some of the functions in usethis that detect if the location provided is at the project/package level.

Comment thread R/insertStructure.R
}

# Set up structure at specified project path
cli::cli_h1("Setting up study package structure")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cli structure, is very clean

Comment thread R/insertStructure.R
dir.create(file.path(path, "inst/concept_sets"))
# extras/
dir.create(file.path(path, "extras"))
invisible(file.create(file.path(path, "extras/CodeToRun.R")))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a later iteration probably we can plug the actual file with some empty basic functions.

Comment thread R/insertStructure.R

usethis::use_testthat()

if (!dir.exists(file.path(path, "R")) | length(list.files(file.path(path, "R"))) == 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this check is good. Also valuable if this function is exported and we could run this functions separately. But maybe in insert structure, there could be a check that we have R/objective files before actually running this function so it is more clear if there's an error. But for this iteration I think is good.

Comment thread tests/testthat/test-insertStructure.R Outdated
}

# De-comment to reset testPackage structure before testing again
# unlink(file.path(test_pkg_path, c("extras", "inst", "tests")), recursive = TRUE, force = TRUE)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why so many unlink() functions? I think for this general test we could just delete the whole testPackage folder to make it more agile.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the reason was it's a bit tricky to create a package from scratch within the code, because both usethis::create_package() and renv::init() are meant to be used interactively and restart the R session by default, interrupting the execution flow. There are parameters to suppress that behaviour, but then there were problems with installPackageBundle() to use renv. So for the moment, to write tests that could run automatically, the functions assume that a package already exists with its core elements. But I can work more on it in the next iteration

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the following commit, the test creates a temporary project. Let's see how that works.

@cebarboza

cebarboza commented Jul 1, 2026

Copy link
Copy Markdown
Member

@laacri Also the Github actions seems to be failing because there's no usethis in the description nor in the renv. I can include it and push the change, also with one unlink() in the test to delete the testPackage folder.

@laacri

laacri commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

@cebarboza I see, sorry I'm not yet too familiar with Github actions. Then yes you can include that, but I'm not sure about the unlink() to delete testPackage because it will probably break the test in test-insertStructure.R

@cebarboza

Copy link
Copy Markdown
Member

@laacri I made some modifications to the temporary project. I modified the insertPackageBundle so renv installs to the project explicitely. Maybe later we can check if it installs correctly only with "." as the default parameter for "path"

@cebarboza
cebarboza merged commit 543e84d into develop Jul 3, 2026
4 checks passed
@cebarboza
cebarboza deleted the 21-function-to-create-extra-files-for-study-package branch July 3, 2026 14:42
@cebarboza cebarboza linked an issue Jul 3, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

2 participants